import sim, sim_items, main
from util import *
import random

class BatteredPrefix(sim_items.Prefix):
    """
    "battered" prefix degrades armor by reducing its PV or EV (whichever would
    normally be greater) by 1-3 points. This CAN make PV or EV negative.
    """
    def __init__(self):
        super(BatteredPrefix, self).__init__(
            "battered", # name
            "This %(wearable)s looks like it's seen better days, as it suffers "
            "from a number scuffs, dents, and thin spots."
        )

    def initialize(self, wearable):
        if not isinstance(wearable, sim_items.Armor):
            raise ValueError('Tried to apply %r to non-armor item: %r' % (self,
                wearable))

        super(BatteredPrefix, self).initialize(wearable)
        self.penalty = random.randint(1,3) 
        if self.wearable.bonuses['evMod'] > self.wearable.bonuses['pvMod']:
            self.affectedMod = 'evMod'
        else:
            self.affectedMod = 'pvMod'
            
        self.wearable.bonuses.update({
            self.affectedMod: \
                    self.wearable.bonuses[self.affectedMod] - self.penalty
        })

    def remove(self, wearable):
        super(BatteredPrefix, self).remove(wearable)
        wearable.bonuses.update({
            self.affectedMod: \
                    self.wearable.bonuses[self.affectedMod] + self.penalty
        })

#========================================
thingClass = BatteredPrefix

